using System;
using NUnit.Framework;
using PhillyCodeCamp.Infrastructure;
using PhillyCodeCampSpecs.Helpers;

namespace PhillyCodeCampSpecs
{
    [TestFixture]
    public class When_Exception_Exists
    {
        private FakeContextProvider _contextProvider;
        private StubLogger _logger;
        private ExceptionHandler _exceptionHandler;

        [Test]
        public void Should_Log_Error()
        {
            _exceptionHandler.HandleError(new Exception());

            Assert.IsTrue(_logger.WasCalled);
        }

        [Test]
        public void Should_redirect_to_error_page()
        {
            _exceptionHandler.HandleError(new Exception());
            Assert.IsNotNull(((FakeContext)_contextProvider.Current).LastRedirectedUrl);
        }

        [TestFixtureSetUp]
        public void Context ()
        {
            _contextProvider = new FakeContextProvider();
            _contextProvider.SetTheCurrentContext(new FakeContext());

            _logger = new StubLogger();

            _exceptionHandler = new ExceptionHandler(_contextProvider, _logger);
        }
    }
}